package com.songlanyun.modules.account.controller.api;

import java.util.Arrays;

import com.songlanyun.common.validator.group.AppGroup;
import com.songlanyun.modules.account.model.dto.PointGiveAwayDTO;
import com.songlanyun.modules.account.model.vo.PointGiveAwayComputerVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.songlanyun.common.utils.R;
import com.songlanyun.common.validator.ValidatorUtils;
import com.songlanyun.modules.account.controller.common.AbstractApiController;
import com.songlanyun.modules.account.entity.UserIdentityAssetEntity;
import com.songlanyun.modules.account.model.dto.SetUpPaymentPasswordDTO;
import com.songlanyun.modules.account.service.UserIdentityAssetService;



/**
 * 会员的资产表（记录余额，一级分拥所得，二级分拥所得等）
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2020-11-03 10:01:15
 */
@RestController
@RequestMapping("api/account/useridentityasset")
public class UserIdentityAssetApiController extends AbstractApiController {
    @Autowired
    private UserIdentityAssetService userIdentityAssetService;


    /**
     * 信息
     */
    @RequestMapping("/info")
//    @RequiresPermissions("account:userIdentityAsset:info")
    public R info(){
        UserIdentityAssetEntity userIdentityAsset = userIdentityAssetService.getById(getUserId(false));

        return R.ok().put("userIdentityAsset", userIdentityAsset);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("account:userIdentityAsset:save")
    public R save(@RequestBody UserIdentityAssetEntity userIdentityAsset){
        userIdentityAssetService.save(userIdentityAsset);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("account:userIdentityAsset:update")
    public R update(@RequestBody UserIdentityAssetEntity userIdentityAsset){
        ValidatorUtils.validateEntity(userIdentityAsset);
        userIdentityAssetService.updateById(userIdentityAsset);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("account:userIdentityAsset:delete")
    public R delete(@RequestBody Long[] ids){
        userIdentityAssetService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 设置支付密码
     */
    @PutMapping("/setUpPaymentPassword")
    public R setUpPaymentPassword(@RequestBody SetUpPaymentPasswordDTO dto) {
        ValidatorUtils.validateEntity(dto, AppGroup.class);
        Long userId = getUserId(true);
        dto.setUserId(userId);
        userIdentityAssetService.setUpPaymentPassword(dto);
        return R.ok();
    }


    /**
     * 积分转赠计算
     * @param dto
     * @return
     */
    @PostMapping("/pointGiveAwayComputer")
    public R pointGiveAwayComputer(@RequestBody PointGiveAwayDTO dto) {
        PointGiveAwayComputerVO vo = userIdentityAssetService.pointGiveAwayComputer(getUserId(true),dto);
        return R.ok().put("data", vo);
    }

    /**
     * 积分转赠
     * @param dto
     * @return
     */
    @PostMapping("/pointGiveAway")
    public R pointGiveAway(@RequestBody PointGiveAwayDTO dto) {

//        ValidatorUtils.validateEntity(dto);
//        userIdentityAssetService.pointGiveAway(getUserId(true),dto);
//        return R.ok();
        return R.error("该功能已关闭");
    }


}
